﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->

<title>維護系統</title>

<script type="text/javascript">
$(document).ready(function() {
	
	if ($.cookie("userId") == null) {
		alert("請先登入系統");
		location.assign("index.html");
	} else {
		initPage("維護系統");
	}
}).tooltip();
</script>

</head>
<body>
<div id="header"></div>
<p>
<table id="grid1"></table>
<div id="pager"></div>
<form id="kk">
<input id="AAAA" type="hidden" >
<input id="HHHH" type="hidden" >
</form>
<script type="text/javascript">

$("#grid1").jqGrid({
	url:'QueryBSS',
	datatype: "json",
	type: "post",
   	colNames:['系統ID', '系統名稱'],
   	colModel:[
   		{name:'AAAA',index:'AAAA',key:true,editable:true,editrules:{required:true}},
   		{name:'HHHH',index:'HHHH',editable:true,editrules:{required:true}}
   	],
   	rowNum:6,
   	pager: '#pager',
   	forceFit: true,
   	rownumbers: true,
   	viewrecords: true,	
    caption:"設定系統"
});

function checkDuplicated() {
	var sysId = $("#AAAA").val();
	var ll = $("#grid1").jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == sysId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(sysId+"已經存在，系統ID不可重覆 !");
	} else {
		var sysName = $("#HHHH").val();
		var dataAdd = {"AAAA":sysId,"HHHH":sysName,"loginUser":$.cookie("userId")};
		var _iCount = $("#grid1").jqGrid('getGridParam', 'records');
		$("#grid1").jqGrid('addRowData', _iCount+1,dataAdd);
		$("form#kk input#AAAA").val(sysId);
	} 
	return [];
}

jQuery("#grid1").navGrid('#pager',{add:true,edit:true,del:true,search:false,refresh:false}
	,{	// Edit
		url: "ManipulateGrid",
		mtype: "POST",
		editData: { 
			currentUser: function() { return $.cookie("userId"); }
		},
		onclickSubmit:function() {
			var sysId = $("#AAAA").val();
			var sysName = $("#HHHH").val();
			var dataAdd = {"AAAA":sysId,"HHHH":sysName,"loginUser":$.cookie("userId")};
			$("#grid1").jqGrid('setRowData', sysId,dataAdd);
		}
	}
	,{	// add
		url: "ManipulateGrid",
		mtype: "POST",
		editData: { 
			currentUser: function() { return $.cookie("userId"); }
		},
		onclickSubmit:function() {
			checkDuplicated();
		}
	},{	// del
		url: "ManipulateGrid",
		mtype: "POST",
		delData: { 
			currentUser: function() { return $.cookie("userId"); }
		}
	}
);


</script>



</body>
</html>